package top.yaofengqiao.springcloudsimple.auth.biz.domain.security.provider;

import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import top.yaofengqiao.springcloudsimple.auth.biz.domain.security.model.MultiUserTypeAuthenticationToken;

/**
 * @author yfq
 * @date 2024/6/6 13:48
 * @description 管理员认证Provider
 */
@Component
public class AdminAuthenticationProvider extends DaoAuthenticationProvider {

    public AdminAuthenticationProvider(UserDetailsService adminUserDetailService) {
        setUserDetailsService(adminUserDetailService);
        setPasswordEncoder(new BCryptPasswordEncoder());
    }

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        return super.authenticate(authentication);
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return MultiUserTypeAuthenticationToken.class.isAssignableFrom(authentication);
    }
}
